package com.ab;

import com.sun.istack.internal.NotNull;

import java.awt.*;
import java.util.Arrays;
import java.util.Iterator;


public class BinaryPoint implements Iterator<BinaryPoint>, Iterable<BinaryPoint> {
    private final boolean[] coords;

    public boolean[] getCoords() {
        return coords;
    }

    public BinaryPoint(boolean... coords) {
        if (coords.length == 0) {
            throw new IllegalArgumentException("Point must not be Null");
        }
        this.coords = coords;
    }

    public Iterator<BinaryPoint> iterator() {
        return this;
    }

    public boolean hasNext() {
        int i = coords.length - 1;
        while (i >= 0 && coords[i]) {
            i--;
        }
        return i >= 0;
    }

    public BinaryPoint next() {
        if (!this.hasNext()) {
            return null;
        }
        boolean[] nextCoords = this.coords.clone();
        int i = this.coords.length - 1;
        while (this.coords[i]) {
            nextCoords[i] = false;
            i--;
        }
        nextCoords[i] = true;
        return new BinaryPoint(nextCoords);
    }

    public void remove() {
    }

    public static BinaryPoint createZeroPoint(int dimension) {
        return new BinaryPoint(new boolean[dimension]);
    }


    public static boolean isConnected(BinaryPoint pointOne, BinaryPoint pointTwo) {
        return false;

    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        BinaryPoint that = (BinaryPoint) o;

        return Arrays.equals(coords, that.coords);

    }

    @Override
    public int hashCode() {
        return coords != null ? Arrays.hashCode(coords) : 0;
    }

    public static void main(String[] args) {


//        System.out.println(Arrays.toString(zero.coords));
//        System.out.println(Arrays.toString(zero.next().coords));
//        BinaryPoint nextZero = zero.next();
//        BinaryPoint nextManual = new BinaryPoint(false, false, true);
//        System.out.println(nextZero.getCoords());
//        System.out.println(nextManual.getCoords());
    }

//    TODO: написать тесты блеать
}
